/**
 * 
 */
package de.nak.fireDepartment.dao;

import java.util.Collection;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import de.nak.fireDepartment.model.Car;

/**
 * Car data access object.
 * @author Sven Redelin
 */
public class CarDAO extends HibernateDaoSupport {
	
	/**
	 * Finds and returns all Cars.
	 * @return a list of cars
	 */
	@SuppressWarnings("unchecked")
	public Collection<Car> findAll() {
		return (Collection<Car>)getHibernateTemplate().find("from Car");
	}
	
	/**
	 * Finds a Car with the given id.
	 * @param carId The id.
	 * @return a Car object or <code>null</code>.
	 */
	public Car findById(Long carId) {
		return (Car)getHibernateTemplate().get(Car.class, carId);
	}
	
	/**
	 * Persists the given car object.
	 * @param car The car.
	 */
	public void save(Car car) {
		getHibernateTemplate().save(car);
	}
	
	/**
	 * Deletes the given car object.
	 * @param car The car.
	 */
	public void delete(Car car) {
		getHibernateTemplate().delete(car);
	}
}
